﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace MVVMPractice.Base
{
    public class WindowProvider
    {
        static Dictionary<string, WindowInfo> types = new Dictionary<string, WindowInfo>();
        public static void Register<T>(string key = "", Window owner = null)
        {
            if (string.IsNullOrEmpty(key))
            {
                key = typeof(T).Name;
            }

            if (!types.ContainsKey(key))
                types.Add(key, new WindowInfo() { WinType = typeof(T), Owner = owner });

        }

        public static void ShowWindow(string key)
        {
            if (types.ContainsKey(key))
            {
                var info = types[key];
                var win = (Window)Activator.CreateInstance(info.WinType);
                if (info.Owner!= null)
                {
                    win.Owner = info.Owner;
                }
                win.Show();
            }
        }
    }

    class WindowInfo
    {
        public Type WinType { get; set; }
        public Window Owner { get; set; }
    }
}
